{layout name="layouts/admin" /}

<!-- jQuery 2.1.4 -->
{js href="/static/admin/plugins/jQuery/jquery-1.9.1.min.js" /}


<!-- 富文本编辑器文件 -->
{js href="/static/admin/ueditor/ueditor.config.js" /}
{js href="/static/admin/ueditor/ueditor.all.js" /}
<style>
    .frame {
        width: 200px;
        height: 30px;
        border: none;
        vertical-align: middle;
    }
    .file{
        position: absolute;
        filter: alpha(opacity:0);
        opacity: 0;
        width: 70px;
        height:40px;
    }
    .coverfile{
        right: 48%;
        top: 21%;
    }
    .radioclass{
        margin-right:20px;
    }
</style>
<div class="panel-heading">{$luckprize?"编辑":"添加"}奖品</div>
<div class="panel-body">
    <form action="/prize/doAddPrize" method="POST" enctype="multipart/form-data" name="prizeimgform">
        <div class="box-body">
            <div class="form-group">
                <label>奖品标题</label>
                <input type="hidden" name="id" value="{$luckprize.id}"/>
                <input type="text" name="prizetitle" value="{$luckprize.prize_title}" class="form-control" placeholder="请输入奖品标题">
            </div>

            <div class="form-group">
                <label>奖品排序方式(数字越大在小程序中显示越靠后,最小0)</label>
                <input type="number" name="sortnum" value="{$luckprize.sort_num}" min="0" class="form-control" >
            </div>

            <div class="form-group" style="clear:both;padding-top:20px;">
                <label>奖品封面图</label>
                    <div>
                        <input type="text" class="form-control" name="prizeimg" id="prizeimg" style="float:left;width:400px;" value="{$luckprize.prize_img}" />
                        <input type="hidden" name="imgfiletype" value="1" />
                        <input type="button" class="btn btn-primary" value="浏览...">
                        <input type="file" name="logofile" class="file coverfile" size="28" onchange="document.getElementById('prizeimg').value=this.value">
                        <input type="button" name="coverimgupload" id="coverimgupload" class="btn btn-primary" style="margin-left: 30px;" value="上传">
                        <iframe id="coverframe" name="coverframe"  class="frame"></iframe>
                    </div>
            </div>

            <div class="form-group">
                <label style="display: block;">选择赞助商</label>
               <select class="form-control" name="sponsorid">
                   <option value="0">请选择</option>
                   {foreach name="sponsors" item="item"}
                   <option value="{$item.id}" {$luckprize.sponsor_id==$item.id?"selected":""}>{$item.sp_name}</option>
                   {/foreach}

               </select>
            </div>

            <div class="form-group">
                <label style="display: block;">开奖方式</label>
                <input type="radio" name="opentype" value="0" id="opentype0"
                       {$luckprize.full_num?"":"checked"}  {$luckprize?"":"checked"}/>
                <label for="opentype0" class="radioclass">&nbsp;按时间自动开奖</label>

                <input type="radio" name="opentype" value="1" id="opentype1"
                       {$luckprize.full_num?"checked":""} />
                <label for="opentype1" class="radioclass">&nbsp;按人数自动开奖</label>
            </div>

            <div class="form-group" id="opentiemdiv">
                <label style="display: block;">开奖时间(时间最长不能超过7天)</label>
                <input type="text" class="form-control" name="opentime" onfocus="WdatePicker({dateFmt:'yyyy-M-d H:mm'}) "value="{$luckprize.open_time}" />
            </div>

            <div class="form-group">
                <label>上线时间</label>
                <input type="text" class="form-control" name="publishtime" onfocus="WdatePicker({dateFmt:'yyyy-M-d H:mm'}) "value="{$luckprize.publish_time}" />
            </div>

            <div class="form-group" id="fullnumdiv" style="display: none">
                <label style="display: block;">开奖人数(若为达到指定人数,则发布7天后自动开奖)</label>
                <input type="text" class="form-control" name="fullnum" value="{$luckprize.full_num}" />
            </div>

            <div class="form-group">
                <label style="display: block;">参与方式</label>
                <input type="radio" name="jointype" value="0" id="jointype0"
                       {$luckprize.prize_type?"":"checked"}  {$luckprize?"":"checked"}/>
                <label for="jointype0" class="radioclass">&nbsp;单人</label>

                <input type="radio" name="jointype" value="1" id="jointype1"
                       {$luckprize.prize_type?"checked":""}/>
                <label for="jointype1" class="radioclass">&nbsp;组队</label>
            </div>

            <div class="form-group" id="teamnumdiv">
                <label style="display: block;">选择组队人数</label>
                {foreach name="teamnumarr" item="item" key="k"}
                <input type="radio" name="teamnum" value="{$k}" id="prizenum{$k}"
                       {$luckprize.prize_num==$k?"checked":""} {$luckprize.prize_num>1?"":($k==2?"checked":"")}/>
                <label for="prizenum{$k}" class="radioclass">&nbsp;{$item}</label>
                {/foreach}
            </div>

            <div class="form-group">
                <label style="display: block;">奖品数量</label>
                <input type="text" id="prizenum" class="form-control" name="prizenum" value="{$luckprize.prize_num?:1}" />
            </div>

            <div class="form-group">
                <label>奖品简介</label>
                <script type="text/plain" name="prizemsg" id="prizemsg" style="width:100%;height:240px;">
    {$luckprize.prize_msg|raw}
</script>
            </div>

            <div class="form-group">
                <button type="submit" id="prizesave" class="btn btn-primary">确认保存</button>
            </div>
        </div>
    </form>
</div>

<script>
    //实例化编辑器
    var prizemsg = UE.getEditor('prizemsg',{autoHeightEnabled:false});

    //奖品封面图上传
    $('#coverimgupload').click(function(){
        document.prizeimgform.action="/sponsor/uploadfiles";
        document.prizeimgform.target="coverframe";
        document.prizeimgform.submit();
    });
    $('#prizesave').click(function(){
        document.prizeimgform.action="/prize/doAddPrize";
        document.prizeimgform.target="";
        document.prizeimgform.submit();
    });

    $(function () {
        var fullnum = {$luckprize.full_num?:0};
        var prizetype = {$luckprize.prize_type?:0};
        if(fullnum==0){
            //按时间开奖
            $("#opentiemdiv").show();
            $("#fullnumdiv").hide();
        }else{
            //按人数开奖
            $("#opentiemdiv").hide();
            $("#fullnumdiv").show();
        }
        if(prizetype==0){
            //单人
            $("#teamnumdiv").hide();
        }else{
            //组团
            $("#teamnumdiv").show();
            $("#prizenum").attr("readonly","readonly");
        }
        $('input[type=radio][name=jointype]').change(function () {
            switch (this.value) {
                case "0":    //单人
                    $("#teamnumdiv").hide();
                    $("#prizenum").val(1);
                    $("#prizenum").removeAttr("readonly");
                    break;
                case "1":    //组团
                    $("#teamnumdiv").show();
                    var prizenum=$("input[type=radio][name=teamnum]").val();
                    $("#prizenum").val(prizenum);
                    $("#prizenum").attr("readonly","readonly");
                    break;
            }
        });
        $('input[type=radio][name=opentype]').change(function () {
            switch (this.value) {
                case "0":    //时间开奖
                    $("#opentiemdiv").show();
                    $("#fullnumdiv").hide();
                    break;
                case "1":    //人数开奖
                    $("#opentiemdiv").hide();
                    $("#fullnumdiv").show();
                    break;
            }
        });
        $('input[type=radio][name=teamnum]').change(function () {
            $("#prizenum").val(this.value);
        });
    })
</script>